home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 740 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: solon.com!not-for-mail
  2. From: Casper.Dik@Holland.Sun.COM (Casper H.S. Dik - Network Security Engineer)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: printf() format extensions - looking for beta testers...
  5. Date: 14 Apr 1996 10:57:17 -0500
  6. Organization: Sun Microsystems, Netherlands
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4kr78t$kao@solutions.solon.com>
  10. References: <4kgljv$l2p@solutions.solon.com> <4klicn$ndl@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes:
  14.  
  15. > >                 format('!', bangcvt);
  16. > > 
  17. > >                 /* do something which can generate an error */
  18. > >                 fprintf(stderr, "%s: %!\n", "open failed");
  19. > >         }
  20.  
  21. >Given the above, how about calls like (well, not a pretty one, but you get the 
  22. >idea...):
  23.  
  24. >    fprintf(stderr, "%-*.2!", something);
  25.  
  26.  
  27. Yes, it seems that the format call back function (bangcvt) should take
  28. a number of flags (leading 0/- found, precision, maximum width) and
  29. a generic way to make the user defined format specifier output characters,
  30. as it can be called from functions like "snprintf", which limit the output.
  31. Passing a buffer to but the output in doesn't strike me as sufficient;
  32. if "bangcvt" can have unlimited output, it must be possible for the
  33. mechanism to cater for that.
  34.  
  35. And, of course, you want a input conversion as well :-)
  36.  
  37. So instead of:
  38.  
  39. > >         int bangcvt(va_list *ap, char *s, int len, fmtspec *f) {
  40.  
  41. You'd get something more like:
  42.  
  43.     bangcvt (va_list *ap, int flags, int width, int precision,
  44.     char fmt, int (*putit)(char c, void *output), void *output)
  45.  
  46. (Where you call "putit" for each character of output with *output
  47. as magic for the call back)
  48.  
  49. Casper
  50. --
  51. Expressed in this posting are my opinions.  They are in no way related
  52. to opinions held by my employer, Sun Microsystems.
  53. Statements on Sun products included here are not gospel and may
  54. be fiction rather than truth.
  55.